#include "addfriendorcreatesessionwidget.h"

AddFriendOrCreateSessionWidget::AddFriendOrCreateSessionWidget(QWidget *parent)
    :QDialog(parent)
{
    // 设置窗口属性
    this->setFixedSize(200, 140);
    this->setWindowTitle("添加好友/创建群聊");
    this->setWindowIcon(QIcon(":/resource/image/logo.png"));
    this->setAttribute(Qt::WA_DeleteOnClose);
    this->setStyleSheet("QWidget { background-color: rgb(255, 255, 255); }");
    this->move(QCursor::pos());

    // 创建布局管理器
    QVBoxLayout *layout = new QVBoxLayout();
    layout->setSpacing(3);
    layout->setContentsMargins(5, 5, 5, 5);
    this->setLayout(layout);

    QString style = "QPushButton { border: none; background-color: rgb(240, 240, 240); }";
    style += "QPushButton:pressed { background-color: rgb(220, 220, 220); }";
    // 创建添加好友按钮
    QPushButton *addFriendBtn = new QPushButton();
    addFriendBtn->setFixedSize(190, 60);
    addFriendBtn->setText("添加好友");
    addFriendBtn->setStyleSheet(style);

    // 创建创建按钮
    QPushButton *createSessionBtn = new QPushButton();
    createSessionBtn->setFixedSize(190, 60);
    createSessionBtn->setText("创建群聊");
    createSessionBtn->setStyleSheet(style);

    layout->addWidget(addFriendBtn);
    layout->addWidget(createSessionBtn);

    // 关联信号槽
    connect(addFriendBtn, &QPushButton::clicked, this, [=](){
        AddFriendWidget *addFriendWidget = new AddFriendWidget(this);
        addFriendWidget->exec();
    });

    connect(createSessionBtn, &QPushButton::clicked, this, [=](){
        ChooseFriendWidget *chooseFriendWidget = new ChooseFriendWidget(this);
        chooseFriendWidget->exec();
    });
}
